//
//  AddTabBar.swift
//  新浪微博
//
//  Created by seteny on 16/7/9.
//  Copyright © 2016年 seteny. All rights reserved.
//

import UIKit

class AddTabBar: UITabBar {

    // MARK: -- 懒加载控件
    lazy var composeButton: UIButton = {
        
        let button = UIButton()
        
        //设置图片
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: .Highlighted)
        //设置背景图片
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Highlighted)
        
        button.sizeToFit()
        return button
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(composeButton)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        //设置撰写按钮的中心点
        composeButton.centerX = width * 0.5
        composeButton.centerY = height * 0.5
        
        //获取系统控件
        //计算控件的宽度
        let itemWith = width / 5
        
        var index = 0
        
        for value in subviews {
            
            //
            if value.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                
                value.x = itemWith * CGFloat(index)
                value.width = itemWith
                
                if index == 1 {
                    index++
                }
                index++
            }
        }
        
        
    }
    
}
